package marking.liu.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class TimeTotalAspect {

    private Long startTime;
    private Long endTime;

    @Pointcut("execution(* marking.liu.service.*.*(..)) && @annotation(marking.liu.annotation.TimeTotal)")
    public void autoFillPointCut() {}

    @Before("autoFillPointCut()")
    public void timeTotalBefore () {
        startTime = System.currentTimeMillis();
    }

    @After("autoFillPointCut()")
    public Long timeTotalEnd() {
        endTime = System.currentTimeMillis() - startTime;
        log.info("执行时长:{}ms", endTime);
        return endTime;
    }
}
